New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

typesafe-exception

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typesafe-exception

Type-safe serialization-friendly Exception class

  • 2.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Type-safe Exception

Because Error class in JavaScript could have been designed better.

Simple serialization-friendly Exception class, with opt-in type-safe details, numeric status code and custom fields.

Examples

import { Exception } from 'typesafe-exception';

// Sometimes it's handy to put all app errors in `errors.ts`, for better centralization and visibility

// Error `name` will be inferred from class name
export class ValidationError extends Exception {
    // Optionally, numeric `status` can be assigned
    status = 400;
}

// Optionally, `details` field can have types

export class AccessDeniedError extends Exception<{ reason: string }> {
    status = 403;
}

throw new AccessDeniedError('You are not allowed here', { reason: 'too boring' });

Keywords

FAQs

Package last updated on 07 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc